﻿using Microsoft.Extensions.DependencyInjection.Extensions;
using Xmart.Expressions.DynamicPredicate;

namespace Microsoft.Extensions.DependencyInjection;

public static class DynamicPredicateServiceCollectionExtensions
{
    /// <summary>
    /// 添加单例动态条件构建器到依赖注入容器，并添加选项到依赖注入容器。
    /// </summary>
    /// <param name="services">依赖注入容器</param>
    /// <param name="setup">选项构建</param>
    /// <returns></returns>
    public static IServiceCollection AddDynamicPredicate(this IServiceCollection services, Action<DynamicPredicateOptions>?setup = null)
    {
        setup ??= options => { };
        services.TryAddScoped<IDynamicPredicateBuilder, DefaultDynamicPredicateBuilder>();
        services.Configure(setup);
        return services;
    }
}
